<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding:0;
        }
        canvas{
            border: 1px solid #ccc;
            box-shadow: 3px 3px 5px 1px #000;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="800" height="500"></canvas>
</body>
</html>
<script>
    let canvas = document.getElementById('canvas');
    let ctx = canvas.getContext('2d');
    ctx.beginPath();
    ctx.arc(200,200,50,0,2*Math.PI);
    ctx.lineWidth = 10;
    ctx.strokeStyle = 'red';
    ctx.stroke();
    ctx.fillStyle  = 'red';
    ctx.fill();

    let ary = [];
    function Circle(x,y,r){
        this.x = x;
        this.y = y;
        this.r = r;
        this.color = `rgb(${Math.floor(Math.random()*249)},${Math.floor(Math.random()*249)},203)`;
        this.dx = Math.random()*10-6;
        this.dy = Math.random()*10 - 6;
        ary.push(this);
    }
    Circle.prototype.render = function () {
        ctx.beginPath();
        ctx.arc(this.x,this.y,this.r,0,2*Math.PI);
        ctx.fillStyle = this.color;
        ctx.fill();
    }
    Circle.prototype.update = function () {
        this.x += this.dx;
        this.y += this.dy;
        this.r--;
        if(this.r<=0){
            ary = ary.filter((item)=>{
                return item !== this;
            })
            return false
        }
        return true;
    }
    canvas.onmousemove = function (e) {
        new Circle(e.clientX,e.clientY,30)
    }
    setInterval(()=>{
        ctx.clearRect(0,0,800,600);
        ary.forEach((item)=>{
            item.update() && item.render();
        })
    },20)
</script>